#! /usr/bin/python

f = open("matrix82.txt", "r")

matrix = []

for l in f:
    matrix.append([int(i) for i in l.split(",")])
f.close()

N = 80
cost = []
for i in range(N):
    cost.append(matrix[i][0])

def min_n(a, b):
    if a>b: return b
    else: return a

for i in range(1, N):
    cost[0] += matrix[0][i]
    for j in range(1, N):
	cost[j] = min_n(cost[j], cost[j-1]) + matrix[j][i]
    for j in range(N-2, -1, -1):
	cost[j] = min_n(cost[j], cost[j+1] + matrix[j][i])

print min(cost)


